package com.yanqu.road.server.cmd.activity.autoreward.rank;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.logic.cross.CrossActivityRankListModel;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.server.manager.activity.ActivityRankMgr;
import com.yanqu.road.server.manager.cross.battle.dunhuangshiku.DunHuangShiKuActivity;
import com.yanqu.road.server.manager.cross.battle.dunhuangshiku.DunHuangShiKuMgr;

/**
 * @author ：zfr
 * @date ：2021/8/12 16:12
 */
public class CrossDunHuangShiKuActivityRank extends BaseCrossRank {

    public CrossDunHuangShiKuActivityRank(int activityId) {
        super(activityId);
    }

    @Override
    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg() {
        //个人积分榜去YRank那边了
        AutoSendRewardProto.CrossUserRankMsg.Builder msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
//        msg.setActivityId(activityId);
//        int conditionType = eGamePlayerEventType.DunHuangShiKuScoreCrossRank.getValue();
//        CrossActivityRankListModel rankListModel = ActivityRankMgr.getCrossActivityNewRankListModel(activityId, conditionType);
//        if (rankListModel != null) {
//            int rank = 0;
//            for (CrossUserRank rankData : rankListModel.getRankList()) {
//                long userId = rankData.getUserId();
//                rank++;
//                addUserRankData(msg, conditionType, userId, rank);
//            }
//        }
//        int teamConditionType = eGamePlayerEventType.DunHuangShiKuTeamScoreCrossRank.getValue();
//        DunHuangShiKuActivity activityInfo = DunHuangShiKuMgr.getDunHuangShiKuActivity(activityId);
//        if (activityInfo != null) {
//            activityInfo.teamRankList.forEach(dunHuangShiKuTeam -> {
//                dunHuangShiKuTeam.memberMap.values().forEach(dunHuangShiKuUser ->
//                        addUserRankData(msg, teamConditionType, dunHuangShiKuUser.baseInfo.getUserId(), dunHuangShiKuTeam.rank)
//                );
//            });
//        }
        return msg;
    }

    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg() {
        return null;
    }

    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg(int groupId) {
        int conditionType = eGamePlayerEventType.DunHuangShiKuScoreCrossRank.getValue();
        AutoSendRewardProto.CrossUserRankMsg.Builder msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
        CrossActivityRankListModel rankListModel = ActivityRankMgr.getCrossActivityNewRankListModel(activityId,
                conditionType);
        msg.setActivityId(activityId);
        if (rankListModel != null) {
            int rank = 0;
            for (CrossUserRank rankData : rankListModel.getRankList()) {
                long userId = rankData.getUserId();
                rank++;
                addUserRankData(msg, conditionType, userId, rank);
            }
        }
        int teamConditionType = eGamePlayerEventType.DunHuangShiKuTeamScoreCrossRank.getValue();
        DunHuangShiKuActivity activityInfo = DunHuangShiKuMgr.getActivity(activityId, groupId);
        if (activityInfo != null) {
            activityInfo.teamRankList.forEach(dunHuangShiKuTeam -> {
                dunHuangShiKuTeam.memberMap.values().forEach(dunHuangShiKuUser ->
                        addUserRankData(msg, teamConditionType, dunHuangShiKuUser.baseInfo.getUserId(), dunHuangShiKuTeam.rank)
                );
            });
        }
        return msg;
    }
}
